package banking;
public class Account {
    private double balance;// 账户余额，用private修饰确保数据封装性
    public Account(double bal) {
        balance = bal;// 创建账户时设置初始余额
    }
    public double getBalance() {
        return balance;// 返回当前账户余额
    }
    public boolean deposit(double amount) {
        balance = balance + amount;// 增加余额
        return true;// 存款总是成功，返回true
    }
    public boolean withdraw(double amount) {
        boolean result = true;
        if (balance < amount) { // 检查余额是否足够
            result = false;// 余额不足，取款失败
        } else {
            balance = balance - amount;// 余额足够，扣款
        }
        return result;
    }
    // 添加 main 方法用于测试
    public static void main(String[] args) {
        Account account = new Account(230.0);
        System.out.println("初始余额: " + account.getBalance());
        account.deposit(40.0);
        System.out.println("存款 40 后余额: " + account.getBalance());
        boolean withdrawSuccess = account.withdraw(59.0);
        System.out.println("取款 59 是否成功: " + withdrawSuccess + "，余额: " + account.getBalance());
    }
}